/**
 * Created by DHC on 2017/6/20.
 */
APP.controller('OutPutController', ['$scope', '$rootScope', 'InputService', '$state', 'OnlineService', 'PopupService','OutPutService',
    function ($scope, $rootScope, InputService, $state, OnlineService, PopupService,OutPutService) {

        /***变量声明***/
        $scope.barCode = {
            barCode: ''
        };
        $scope.outData = {
            number: '',
            supplier: '',
            paper: '',
            weight: '',//克重
            specification: '',//规格
            kg: ''//重量
        };

        /**
         * 初始化函数
         */
        $scope.init = function () {
        };


        /**
         * 返回方法
         */
        $scope.goBack = function () {
            $scope.$ionicGoBack();
        };
        /**
         * 按条码查询物料信息
         */
        $scope.getByCode = function () {
            if (!$scope.barCode.barCode) {
                PopupService.showToast('请录入条码');
                return;
            }
            OnlineService.getByCode($scope.barCode.barCode)
                .then(function (response) {
                    console.log('成功回调方法', response);
                    if(response.data.data.state != '在库') {
                        PopupService.showToast('该货物不在库');
                        return;
                    }
                    $scope.outData = response.data.data;
                    console.log('$scope.onlineData', $scope.onlineData);
                }, function (response) {
                    console.log('失败回调方法', response)
                })
        };
        //确认提交
        $scope.outStock = function () {
            if (!$scope.barCode.barCode) {
                PopupService.showToast('请填写必要信息');
                return;
            }
            OutPutService.outStock($scope.barCode.barCode)
                .success(function (response) {
                    console.log('成功回调方法', response);
                    if(response.success) {
                        PopupService.showToast('出库成功');
                        $scope.barCode = {
                            barCode: ''
                        };
                        $scope.outData = {
                            number: '',
                            supplier: '',
                            paper: '',
                            weight: '',//克重
                            specification: '',//规格
                            kg: ''//重量
                        };
                    }
                })
                .error(function (error) {
                    console.log('成功回调方法', error);
                })
        };


        $scope.$on('$ionicView.beforeEnter', function () {
            $scope.init();
        });
    }
]);

/**
 * creater:kunjiang.zhou@dhc.com.cn
 * create time:2017-05-31 19:33:40
 * describe:入库
 */
APP.service('OutPutService', ['$http', 'UrlService', function ($http, UrlService) {
    /**
     * 出库方法
     */
    this.outStock = function (data) {
        var param = {
            barcode: data
        };
        return $http.post(UrlService.getUrl('OUT_STOCK'), param);
    }

}]);
